/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.sportclubmanager.dao;

import cz.muni.fi.pa165.sportclubmanager.entity.Users;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import org.springframework.stereotype.Repository;

/**
 *
 * @author juro
 */
@Repository
public class UsersDAOImpl implements UsersDAO {
    
    @PersistenceContext
    private EntityManager em;

    @Override
    public void createUser(Users u) {
        em.persist(u);
    }

    @Override
    public void updateUser(Users u) {
        em.merge(u);
    }

    @Override
    public void removeUser(Users u) {
        Users user = em.merge(u);
        em.remove(user);
    }

    @Override
    public List<Users> getUsers() {
        Query query = em.createQuery("SELECT u FROM Users u");
        List<Users> users = (List<Users>) query.getResultList();

        return users;
    }

    @Override
    public Users find(String name) {
        if(name == null)return null;
        Users user = em.find(Users.class, name);
        return user;
    }
    
    


    
    
}
